package piwan;

import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.util.ArrayList;

public class CompHandler extends EventHandler {
	public CompHandler() {
		hdls = new ArrayList<EventHandler>();
	}
	
	public ArrayList<EventHandler> getHandlers() { return hdls; }
	
	public void add( EventHandler h ) { hdls.add(h); }
	public void remove( EventHandler h ) { hdls.remove(h); }
	public void clear() { hdls.clear(); }
	
	public boolean onMousePressed( MouseEvent ev  ) {
		if( hdls.size() == 0 ) return false;
		for(EventHandler h: hdls)
			if( h.onMousePressed(ev) )
				return true;
		return false;
	}
	
	public boolean onMouseWheel( MouseWheelEvent ev ) {
		if( hdls.size() == 0 ) return false;
		for(EventHandler h: hdls)
			if( h.onMouseWheel(ev) )
				return true;
		return false;
	}
	
	public boolean onMouseReleased( MouseEvent ev ) {
		if( hdls.size() == 0 ) return false;
		for(EventHandler h: hdls)
			if( h.onMouseReleased(ev) )
				return true;
		return false;
	}
	
	public boolean onMouseMotion(MouseEvent ev) {
		if( hdls.size() == 0 ) return false;
		for(EventHandler h: hdls)
			if( h.onMouseMotion(ev) )
				return true;
		return false;
	}
	
	public boolean onKeyPressed( KeyEvent ev )  {
		if( hdls.size() == 0 ) return false;
		for(EventHandler h: hdls)
			if( h.onKeyPressed(ev) )
				return true;
		return false;
	}
	
	public boolean onKeyReleased( KeyEvent ev )  {
		if( hdls.size() == 0 ) return false;
		for(EventHandler h: hdls)
			if( h.onKeyReleased(ev) )
				return true;
		return false;
	}
	
	public boolean onQuit()  {
		if( hdls.size() == 0 ) return false;
		for(EventHandler h: hdls)
			if( h.onQuit() )
				return true;
		return false;
	}
	
	
	private ArrayList<EventHandler> hdls;
}
